<template>
  <div class="user-list-container">
    <!-- 表格 -->
    <el-card shadow="never" class="table-card">
      <el-table
        v-loading="loading"
        :data="tableData"
        border
        class="table"
      >
        <el-table-column prop="complaint_feedback_id" label="ID" width="80" />
        <el-table-column prop="complaint_feedback_content" label="反馈内容" />
        <el-table-column label="联系方式" width="120">
          <template #default="scope">
            {{ encryptPhone(scope.row.complaint_feedback_phone) }}
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="创建时间" width="180" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button link @click="handleView(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      />
    </el-card>

    <!-- 查看反馈详情对话框 -->
    <el-dialog
      v-model="dialogVisible"
      title="反馈详情"
      width="600"
    >
      <el-descriptions :column="1" border>
        <el-descriptions-item label="反馈内容">
          {{ currentRow.complaint_feedback_content }}
        </el-descriptions-item>
        <el-descriptions-item label="联系方式">
          {{ currentRow.complaint_feedback_phone }}
        </el-descriptions-item>
        <el-descriptions-item label="创建时间">
          {{ currentRow.created_at }}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import tableMixin from "@/mixins/tableMixin";
import api from "@/request/api.js";

export default {
  name: "FeedbackList",
  mixins: [tableMixin],
  data() {
    return {
      // 当前查看的行数据
      currentRow: {},
      // 对话框显示状态
      dialogVisible: false,
      // 查询参数
      queryParams: {},
      apimodel: "tsfklb",
      apival: "orderList",
    };
  },
  created() {
    this.getTableData();
  },
  methods: {
    // 加密手机号（显示前3位和后4位，中间用****代替）
    encryptPhone(phone) {
      if (!phone) return '';
      return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
    },
    
    // 查看反馈详情
    handleView(row) {
      this.currentRow = { ...row }; // 复制一行数据，避免直接修改引用
      this.dialogVisible = true;
    },
    
    // 获取表格数据（需要覆盖tableMixin中的方法）
    async getTableData() {
      this.loading = true;
      try {
        const params = {
          page: this.page,
          size: this.pageSize,
          ...this.queryParams
        };
        
        const res = await api[this.apimodel][this.apival](params);
        if (res.data.code === 200) {
          this.tableData = res.data.content.data || [];
          this.total = res.data.content.total || 0;
        }
      } catch (error) {
        console.error("获取数据失败:", error);
        this.$message.error("获取数据失败");
      } finally {
        this.loading = false;
      }
    },
    
    // 以下方法覆盖tableMixin中的默认实现，因为当前页面不需要
    handleSizeChange(val) {
      this.pageSize = val;
      this.getTableData();
    },
    
    handleCurrentChange(val) {
      this.page = val;
      this.getTableData();
    }
  }
};
</script>

<style scoped>
.user-list-container {
  padding: 20px;
}
.table-card {
  margin-bottom: 20px;
}
.pagination {
  margin-top: 20px;
  text-align: right;
}
</style>